/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package transaction.customer_documents;

import java.awt.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import template.RegistrantionPanel;
import transaction.customer_documents.object.MCustomerDocument;
import transaction.customer_documents.object.TCustomerDocument;

/**
 *
 * @author Madushanka
 */
public class CustomerDocuments extends RegistrantionPanel {

    /**
     * Creates new form client_documents
     */
    public CustomerDocuments() {
        initComponents();
        initOthrs();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked") 
    private void initOthrs() {
        tcustomerdocuments = new TCustomerDocument();
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        sSelectBox1 = new component.display_component.sSelectBox();

        jLabel1.setText("Customer :");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Code", "Name", ""
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sSelectBox1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(sSelectBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private component.display_component.sSelectBox sSelectBox1;
    // End of variables declaration//GEN-END:variables

    private transaction.customer_documents.object.TCustomerDocument tcustomerdocuments;
    @Override
    public Object initObject() {

        return tcustomerdocuments;
    }

    @Override
    public Object[] initObjectList() {
        int row = jTable1.getRowCount();
        TCustomerDocument document = new TCustomerDocument();
        ArrayList<TCustomerDocument> documents = null;
        DefaultTableModel df = (DefaultTableModel) jTable1.getModel();
        for (int i = 0; i < row; i++) {
            if(df.getValueAt(i, 2).toString().equals("1")){
                document.setCustomer(sSelectBox1.getCode());
                document.setDocument(df.getValueAt(i, 0).toString());
                document.setStatus(CustomerDocumentStatus.ACTIVE);
                documents.add(document);
            }
        }
        Object[] o = documents.toArray();
        return o;
    }

    
    @Override
    public List<Component> getOtherComponent() {
        return Arrays.asList();
    }

    @Override
    public List<Component> getIdentityComponent() {
        return Arrays.asList(
                (Component) sSelectBox1
        );
    }

    @Override
    public List<Component> getEsentialComponent() {
        return Arrays.asList(
                (Component) sSelectBox1
        );
    }
   
    @Override
    public void getUnbindObject(Object object) {
        
    }

    @Override
    public void bindComponents(ArrayList<Object> list, int index) {
        tcustomerdocuments = (TCustomerDocument) list.get(index);
    }

    @Override
    public List<Component> componentList() {
        return Arrays.asList(
                (Component) sSelectBox1,
                (Component) jTable1
        );
    }
}
